DataTable.Select 方法 (System.Data)

您所在的位置:网站首页 offset row column DataTable.Select 方法 (System.Data)

DataTable.Select 方法 (System.Data)

2023-03-29 22:16| 来源: 网络整理| 查看: 265

获取由与筛选条件匹配的所有 DataRow 对象组成的数组。

public: cli::array ^ Select(System::String ^ filterExpression); public System.Data.DataRow[] Select (string? filterExpression); public System.Data.DataRow[] Select (string filterExpression); member this.Select : string -> System.Data.DataRow[] Public Function Select (filterExpression As String) As DataRow() 参数 filterExpression String

用于筛选行的条件。 有关如何筛选行的示例,请参阅 DataView RowFilter 语法 [C#]。

返回 DataRow[]

一个 DataRow 对象数组。

示例

以下示例使用筛选器表达式返回对象的数组 DataRow 。

private void GetRowsByFilter() { DataTable table = DataSet1.Tables["Orders"]; // Presuming the DataTable has a column named Date. string expression; expression = "Date > #1/1/00#"; DataRow[] foundRows; // Use the Select method to find all rows matching the filter. foundRows = table.Select(expression); // Print column 0 of each returned row. for(int i = 0; i < foundRows.Length; i ++) { Console.WriteLine(foundRows[i][0]); } } Private Sub GetRowsByFilter() Dim table As DataTable = DataSet1.Tables("Orders") ' Presuming the DataTable has a column named Date. Dim expression As String expression = "Date > #1/1/00#" Dim foundRows() As DataRow ' Use the Select method to find all rows matching the filter. foundRows = table.Select(expression) Dim i As Integer ' Print column 0 of each returned row. For i = 0 to foundRows.GetUpperBound(0) Console.WriteLine(foundRows(i)(0)) Next i End Sub 注解

若要创建 filterExpression 参数,请使用适用于 DataColumn 类的 Expression 属性值的相同规则来创建筛选器。

若要确保正确的排序顺序,请使用 Select(String, String) 或 Select(String, String, DataViewRowState)指定排序条件。

如果筛选器上的列包含 null 值,则它不会是结果的一部分。

另请参阅 CaseSensitive DataTables Null 值 适用于


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3